package com.example.hxds.mis.api.controller;

import cn.dev33.satoken.annotation.SaCheckPermission;
import cn.dev33.satoken.annotation.SaMode;
import com.example.hxds.common.util.PageUtils;
import com.example.hxds.common.util.R;
import com.example.hxds.mis.api.controller.form.*;
import com.example.hxds.mis.api.service.VoucherService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.validation.Valid;
import java.util.HashMap;

/**
 * @Author XUYANG
 * @Date 2024-04-08 19:01
 */
@RestController
@RequestMapping("/voucher")
@Tag(name = "VoucherController", description = "代金券Web接口")
public class VoucherController {
    @Resource
    private VoucherService voucherService;
    @PostMapping("/searchVoucherByPage")
    @Operation(summary = "查找代金券分页数据")
    @SaCheckPermission(value = {"ROOT", "VOUCHER:SELECT"}, mode = SaMode.OR)
    public R searchVoucherByPage(@Valid @RequestBody SearchVoucherByPageForm form) {
        PageUtils res=voucherService.searchVoucherByPage(form);
        return R.ok().put("result",res);
    }
    @PostMapping("/insertVoucher")
    @Operation(summary = "添加代金券")
    @SaCheckPermission(value = {"ROOT", "VOUCHER:INSERT"}, mode = SaMode.OR)
    public R insertVoucher(@Valid @RequestBody InsertVoucherForm form) {
        form.setStatus((byte)3);
        int rows=voucherService.insertVoucher(form);
        return R.ok().put("rows",rows);
    }
    @PostMapping("/updateVoucherStatus")
    @Operation(summary = "更新代金券状态")
    @SaCheckPermission(value = {"ROOT", "VOUCHER:UPDATE"}, mode = SaMode.OR)
    public R updateVoucherStatus(@Valid @RequestBody UpdateVoucherStatusForm form) {
        int rows=voucherService.updateVoucherStatus(form);
        return R.ok().put("rows",rows);
    }
    @PostMapping("/deleteVoucherByIds")
    @Operation(summary = "删除代金券")
    @SaCheckPermission(value = {"ROOT", "VOUCHER:DELETE"}, mode = SaMode.OR)
    public R deleteVoucherByIds(@Valid @RequestBody DeleteVoucherByIdsForm form) {
        int rows=voucherService.deleteVoucherByIds(form);
        return R.ok().put("rows",rows);
    }
}
